package com.thinkingcoder.tcsharding.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.thinkingcoder.tcsharding.datasource.ShardingDataSource;
import com.thinkingcoder.tcsharding.engine.ShardingEngine;
import com.thinkingcoder.tcsharding.engine.StandardShardingEngine;
import com.thinkingcoder.tcsharding.orm.mybatis.SqlStatementInterceptor;
import com.thinkingcoder.tcsharding.property.ShardingProperties;

/**
 * sharding auto configuration.
 */
@Configuration
@EnableConfigurationProperties({ShardingProperties.class})
public class ShardingAutoConfiguration {

    @Bean
    public ShardingDataSource shardingDataSource(@Autowired ShardingProperties properties) {
        return new ShardingDataSource(properties);
    }

    @Bean
    public SqlStatementInterceptor sqlStatementInterceptor() {
        return new SqlStatementInterceptor();
    }

    @Bean
    public ShardingEngine shardingEngine(@Autowired ShardingProperties properties) {
        return new StandardShardingEngine(properties);
    }

}
